<template>
  <view class="personal-center">
    <view class="header">
      <view class="user-info">
        <view class="avatar">
          <image src="/static/images/avatar.png" mode="aspectFill"></image>
        </view>
        <view class="login-register">
          <text class="welcome">欢迎您</text>
          <view class="auth-buttons">
            <text class="login-btn" @click="navigateToLogin">登录</text>
            <text class="divider">/</text>
            <text class="register-btn" @click="navigateToRegister">注册</text>
          </view>
        </view>
      </view>
    </view>
    
    <view class="orders">
      <view class="order-header">
        <text class="order-title">我的订单</text>
        <text class="view-all" @click="viewAllOrders">查看全部订单 ></text>
      </view>
      <view class="order-list">
        <view class="order-item" v-for="(item, index) in orderStatus" :key="index" @click="navigateToOrder(item.type)">
          <view class="order-icon">{{ item.icon }}</view>
          <text class="order-text">{{ item.text }}</text>
        </view>
      </view>
    </view>
    
    <view class="settings">
      <view class="setting-group">
        <view class="setting-item" v-for="(item, index) in settings" :key="index" @click="handleSetting(item.type)">
          <text class="setting-icon">{{ item.icon }}</text>
          <text class="setting-text">{{ item.text }}</text>
          <text class="setting-arrow">></text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      orderStatus: [
        { icon: '💰', text: '待付款', type: 'unpaid' },
        { icon: '🚚', text: '待发货', type: 'unshipped' },
        { icon: '📦', text: '已发货', type: 'shipped' },
        { icon: '✅', text: '交易完成', type: 'completed' },
        { icon: '❌', text: '交易关闭', type: 'closed' }
      ],
      settings: [
        { icon: '👤', text: '个人资料', type: 'profile' },
        { icon: '🔒', text: '修改密码', type: 'password' },
        { icon: '📱', text: '绑定手机', type: 'phone' },
        { icon: '📍', text: '收货地址', type: 'address' },
        { icon: '💳', text: '我的钱包', type: 'wallet' },
        { icon: '❌', text: '退出登录', type: 'logout' }
      ]
    };
  },
  methods: {
    navigateToLogin() {
      uni.navigateTo({
        url: '/pages/login/login'
      });
    },
    navigateToRegister() {
      uni.navigateTo({
        url: '/pages/register/register'
      });
    },
    viewAllOrders() {
      uni.navigateTo({
        url: '/pages/orders/orders'
      });
    },
    navigateToOrder(type) {
      uni.navigateTo({
        url: `/pages/orders/orders?type=${type}`
      });
    },
    handleSetting(type) {
      if (type === 'logout') {
        uni.showModal({
          title: '提示',
          content: '确定要退出登录吗？',
          success: (res) => {
            if (res.confirm) {
              // 处理退出登录逻辑
              uni.navigateTo({
                url: '/pages/login/login'
              });
            }
          }
        });
      } else {
        uni.navigateTo({
          url: `/pages/settings/${type}`
        });
      }
    }
  }
};
</script>

<style>
.personal-center {
  min-height: 100vh;
  background-color: #f8f8f8;
}

.header {
  background: linear-gradient(135deg, #4CAF50, #45a049);
  padding: 40rpx 30rpx;
  color: white;
}

.user-info {
  display: flex;
  align-items: center;
}

.avatar {
  width: 120rpx;
  height: 120rpx;
  border-radius: 50%;
  overflow: hidden;
  border: 4rpx solid rgba(255,255,255,0.3);
  margin-right: 30rpx;
}

.avatar image {
  width: 100%;
  height: 100%;
}

.welcome {
  font-size: 32rpx;
  margin-bottom: 10rpx;
  display: block;
}

.auth-buttons {
  display: flex;
  align-items: center;
}

.login-btn, .register-btn {
  font-size: 28rpx;
  padding: 10rpx 20rpx;
  background-color: rgba(255,255,255,0.2);
  border-radius: 30rpx;
  margin: 0 10rpx;
}

.divider {
  color: rgba(255,255,255,0.5);
  margin: 0 10rpx;
}

.orders {
  background-color: #fff;
  margin: 20rpx;
  border-radius: 20rpx;
  padding: 20rpx;
  box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.05);
}

.order-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20rpx 0;
  border-bottom: 1rpx solid #f5f5f5;
}

.order-title {
  font-size: 32rpx;
  font-weight: bold;
}

.view-all {
  font-size: 24rpx;
  color: #999;
}

.order-list {
  display: flex;
  justify-content: space-around;
  padding: 30rpx 0;
}

.order-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.order-icon {
  font-size: 40rpx;
  margin-bottom: 10rpx;
}

.order-text {
  font-size: 24rpx;
  color: #666;
}

.settings {
  background-color: #fff;
  margin: 20rpx;
  border-radius: 20rpx;
  padding: 20rpx;
  box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.05);
}

.setting-group {
  padding: 10rpx 0;
}

.setting-item {
  display: flex;
  align-items: center;
  padding: 30rpx 20rpx;
  border-bottom: 1rpx solid #f5f5f5;
}

.setting-item:last-child {
  border-bottom: none;
}

.setting-icon {
  font-size: 36rpx;
  margin-right: 20rpx;
  width: 40rpx;
  text-align: center;
}

.setting-text {
  flex: 1;
  font-size: 28rpx;
  color: #333;
}

.setting-arrow {
  color: #999;
  font-size: 24rpx;
}
</style>